package com.ruoyi.project.good.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.good.domain.GoodHis;
import com.ruoyi.project.good.service.IGoodHisService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 操作历史Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/good/his")
public class GoodHisController extends BaseController
{
    @Autowired
    private IGoodHisService goodHisService;

    /**
     * 查询操作历史列表
     */
    @PreAuthorize("@ss.hasPermi('good:his:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodHis goodHis)
    {
        startPage();
        List<GoodHis> list = goodHisService.selectGoodHisList(goodHis);
        return getDataTable(list);
    }

    /**
     * 导出操作历史列表
     */
    @PreAuthorize("@ss.hasPermi('good:his:export')")
    @Log(title = "操作历史", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodHis goodHis)
    {
        List<GoodHis> list = goodHisService.selectGoodHisList(goodHis);
        ExcelUtil<GoodHis> util = new ExcelUtil<GoodHis>(GoodHis.class);
        return util.exportExcel(list, "his");
    }

    /**
     * 获取操作历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:his:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(goodHisService.selectGoodHisById(id));
    }

    /**
     * 新增操作历史
     */
    @PreAuthorize("@ss.hasPermi('good:his:add')")
    @Log(title = "操作历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodHis goodHis)
    {
        return toAjax(goodHisService.insertGoodHis(goodHis));
    }

    /**
     * 修改操作历史
     */
    @PreAuthorize("@ss.hasPermi('good:his:edit')")
    @Log(title = "操作历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodHis goodHis)
    {
        return toAjax(goodHisService.updateGoodHis(goodHis));
    }

    /**
     * 删除操作历史
     */
    @PreAuthorize("@ss.hasPermi('good:his:remove')")
    @Log(title = "操作历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodHisService.deleteGoodHisByIds(ids));
    }
}
